<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Order extends CI_Controller {
	
	function __construct()
	{
		parent::__construct();
	}
	
	/**
	 * 档案入口
	 */
	public function index()
	{
		//$this->idcard();
	}
	
    /**
     * 18.保险订单
     */
    public function reservation($id, $cateid){
        session_start();
        // 下面这一段用于根据国家+省份进行领区的判定，然后根据领区给于预约提示; @2012.11.8
        $city = array('bj'=>'北京','sh'=>'上海','gz'=>'广州','hk'=>'香港','cd'=>'成都','sy'=>'沈阳','wh'=>'武汉','cq'=>'重庆');
        $result = array();
        $country_names = $_SESSION['country_cn_names'];
        $province_name = $_SESSION['province_name']; 
        $arr = explode(",", $country_names);
        $district = $this->db->query("select * from visa_district where country_name in ('".implode("','", $arr)."')")->result_array();
        foreach($district as $row) {   
            $result[$row['country_name']] = array('district'=>'');  
            foreach($city as $k=>$v) {
                if(strpos($row[$k], $province_name) !== false) {
                    $result[$row['country_name']]['district'] = $v;
                }
            }
            $result[$row['country_name']]['remark'] = $this->db->query("select remark from visa_reservation where country_district='".
            $row['country_name']. $result[$row['country_name']]['district']."'")->row()->remark;    
        }
        //print_r($result);
        //exit;
        $this->load->library('fillform',array('id'=>$id));   
        $data = array(
            'id' => $id,
            'cateid' => $cateid,
            'result' => $result,
            'forms' => $this->fillform->getFilled()
        );
        $this->load->view('order_reservation', $data);
    } 
	
	/**
	 * 18.保险订单
	 */
	public function insurance($id, $cateid){
        $this->load->library('fillform',array('id'=>$id));   
        $data = array(
            'id' => $id,
            'cateid' => $cateid,
            'forms' => $this->fillform->getFilled()
        );
		$this->load->view('order_insurance', $data);
	}                                       
	
	/**
	 * 18.机票订单
	 */
	public function ticket($id, $cateid){
        $this->load->library('fillform',array('id'=>$id));   
        $data = array(
            'id' => $id,
            'cateid' => $cateid,
            'forms' => $this->fillform->getFilled()
        );
		$this->load->view('order_ticket', $data);
	}
	
	
	/**
	 * 20.酒店订单
	 */
	public function hotel($id, $cateid){
        $this->load->library('fillform',array('id'=>$id));   
        $data = array(
            'id' => $id,
            'cateid' => $cateid,
            'forms' => $this->fillform->getFilled()
        );        
		$this->load->view('order_hotel', $data);
	}

	/**
	 * 21.行程
	 */
	public function itinery($id, $cateid){
		!(empty($id) || empty($cateid)) || show_error('參數錯誤，请查证后再试' );
		
		$info = null;
		$filled = null;
		if ( !empty($id) ){
			$this->load->model('Order_Itinery_Model','',TRUE);
			$info = $this->Order_Itinery_Model->get_one($id);
			$this->load->library('fillform',array('id'=>$id));
			$filled = $this->fillform->getFilled();
		}
		
		$data = array(
			'id' => $id,
			'cateid' => $cateid,
			'info' => $info,
			'forms' => $filled,
		);
		//print_r($data);
		$this->load->view('order_itinery', $data);
	}
	
	/**
	 * 21.行程更新
	 */
	public function itinery_update($cateid){
		!empty($cateid) || show_error('參數錯誤，请查证后再试' );
		
		//print_r($this->input->post());		
		$id = $this->input->post('id');

		$this->load->model('Order_Itinery_Model','',TRUE);
		$info = $this->Order_Itinery_Model->get_one($id);
		$isExist = (empty($info))?FALSE:TRUE;

		if ( $isExist ){	//insert or update
			$this->Order_Itinery_Model->update_entry($id, $this->input->post());
		}else{
			$this->Order_Itinery_Model->insert_entry($this->input->post());
			//update forms 
			$this->load->model('Archive_Idcard_Model','',TRUE);
			$this->Archive_Idcard_Model->update_forms($id, $cateid);
		}
		redirect('order/itinery/'.$id.'/'.$cateid);
	}	
	

}

/* End of file order.php */
/* Location: ./application/controllers/order.php */